﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace NeonMika.Webserver.ClientLibrary
{
    public class XmlCommand : Command
    {
        public XmlCommand(string url, string name, string[] neededParameters)
            : base("", url, name,neededParameters)
        {
        }

        public XmlCommand(string ip, string url, string name, string[] neededParameters)
            : base(ip, url, name, neededParameters)
        {
        }

        public Dictionary<string, string> LastResponseAsDictionary()
        {
            XElement head =  this.LastResponseAsXDocument().Root;
            Dictionary<string, string> returnDictionray = new Dictionary<string, string>();
            foreach (XElement ele in head.Elements())
                returnDictionray.Add(ele.Name.ToString(), ele.Value);
            return returnDictionray;
        }

        public XDocument LastResponseAsXDocument()
        {
            XDocument xmlDoc = XDocument.Parse(LastResponse);
            return xmlDoc;
        }
    }
}
